from django.core.management.base import BaseCommand
from backend.cews.models import RepairOrderTask
from backend.eform.models import Eform
# from backend.cews.signals import check_repair_order_task # noqa: F401
from django.db import transaction

class Command(BaseCommand):
    help = 'update parts eform status'
    def handle(self, *args, **options):
        rots = RepairOrderTask.objects.filter(eform_id__isnull=False,role=RepairOrderTask.RoleType.TESTER)
        for rot in rots:
            if rot.eform_id and rot.done_by and rot.done_by_datetime:
                eform = Eform.objects.get(id=rot.eform_id)
                if eform.overall_test_result != "":
                    rot.role_result = eform.overall_test_result
            rot.is_endorse_required = False
            with transaction.atomic():
                rot.save()